package cn.jbolt.core.api;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * JWT Parse result
 *
 * @ClassName: JwtParseRet
 * @author: JFinal学院-小木 QQ：909854136
 * @date: 2019年9月13日
 */
public class JBoltJwtParseRet {
	private JBoltApiUser apiUser;
	private boolean expired;
	private boolean signCheckFailed;
	private JBoltApiRet apiRet;

	public boolean isSignCheckFailed() {
		return signCheckFailed;
	}

	public JBoltJwtParseRet setSignCheckFailed(boolean signCheckFailed) {
		this.signCheckFailed = signCheckFailed;
		return this;
	}

	public boolean isExpired() {
		return expired;
	}

	public JBoltJwtParseRet setExpired(boolean expired) {
		this.expired = expired;
		return this;
	}

	public Object getUserId() {
		if (isOk()) {
			return apiUser.getUserId();
		}
		return null;
	}
	@JSONField(serialize = false)
	public <T> T getUserIdAs() {
		if (isOk()) {
			return apiUser.getUserIdAs();
		}
		return null;
	}
	@JSONField(serialize = false)
	public Long getUserIdToLong() {
		if (isOk()) {
			return apiUser.getUserIdToLong();
		}
		return null;
	}
	@JSONField(serialize = false)
	public Integer getUserIdToInt() {
		if (isOk()) {
			return apiUser.getUserIdToInt();
		}
		return null;
	}
	@JSONField(serialize = false)
	public String getUserIdToStr() {
		if (isOk()) {
			return apiUser.getUserIdToStr();
		}
		return null;
	}

	public String getUserSessionKey() {
		if (isOk()) {
			return apiUser.getSessionKey();
		}
		return null;
	}

	public String getPcInnerPlatformUserSessionId() {
		return getUserSessionKey();
	}

	public boolean isOk() {
		return expired == false && signCheckFailed == false && apiUser != null && apiRet == null;
	}

	public JBoltApiUser getApiUser() {
		return apiUser;
	}

	public JBoltJwtParseRet setApiUser(JBoltApiUser apiUser) {
		this.apiUser = apiUser;
		return this;
	}

	public JBoltApiRet getApiRet() {
		return apiRet;
	}

	public JBoltJwtParseRet setApiRet(JBoltApiRet apiRet) {
		this.apiRet = apiRet;
		return this;
	}
}
